package top.kaoshanji.ch06;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import top.kaoshanji.ch06.interfaces.Employee;

import java.util.Arrays;

/**
 * 代码清单 ch06-01：接口示例，实例数组排序(6.1.1节)
 * @see top.kaoshanji.ch06.interfaces.Employee
 * author kaoshanji
 * ^_^
 * create time 2024/11/26 21:09
 */
public class InterfacesTest {

    private static final Logger logger = LogManager.getLogger(InterfacesTest.class);

    public static void main(String[] args) {
        logger.info("...代码清单 ch06-01：接口示例，实例数组排序(6.1.1节)...");

        var staff = new Employee[3];

        staff[0] = new Employee("Harry Hacker", 35000);
        staff[1] = new Employee("Carl Cracker", 75000);
        staff[2] = new Employee("Tony Tester", 38000);

        // sort 方法要求类实现 Comparable 接口，才会被接受
        Arrays.sort(staff);

        for (Employee e: staff) {
            System.out.println("name=" + e.getName() + ",salary=" + e.getSalary());
        }
    }

}
